package com.ruoyi.wx.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.wx.service.IPtClassExpAllService;
import com.ruoyi.wx.service.IPtExpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * @author 莫修
 * @date 2022/3/7
 */
@RestController
@Api(value = "微信首页接口", tags = {"微信首页接口测试"})
@RequestMapping("/wx")
public class WxIndexController {

    @Autowired
    private IPtExpService ptExpService;

    @Autowired
    private IPtClassExpAllService ptClassExpAllService;


    @ApiOperation("获取已预习和未预习的实验以及完成度")
    @GetMapping("/getOpenAndNoOpenExp")
    public AjaxResult getOpenAndNoOpenExp() {
        Long classId = SecurityUtils.getDeptId();
        if (classId == null) {
            return AjaxResult.error("未选择班级！请选择班级后重试");
        }
        long[] ids = ptClassExpAllService.getOneByClassId(classId);
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("老师未选择实验！请联系老师");
        }
        return AjaxResult.success(ptExpService.getPrepAndNoPrepExp(ids));
    }

    @ApiOperation("获取待实验和已实验")
    @GetMapping("/getTreatAndNoTreatExp")
    public AjaxResult getTreatAndNoTreatExp() {
        Long classId = SecurityUtils.getDeptId();
        if (classId == null) {
            return AjaxResult.error("未选择班级！请选择班级后重试");
        }
        long[] ids = ptClassExpAllService.getOneByClassId(classId);
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("老师未选择实验！请联系老师");
        }
        return AjaxResult.success(ptExpService.getTreatAndNoTreatExp(ids));
    }

    @ApiOperation("获取老师已改实验报告的实验")
    @GetMapping("/getEndExp")
    public AjaxResult getEndExp() {
        return AjaxResult.success(ptExpService.getEndExp());
    }

    @ApiOperation("获取以结束的实验的详细分数信息")
    @GetMapping("/getEndExpScore")
    public AjaxResult getEndExpScore(Long expId) {
        return AjaxResult.success(ptExpService.getEndExpScore(expId));
    }

}
